package com.ranyk.www.enums;

import lombok.Getter;

import java.util.Objects;

/**
 * CLASS_NAME: ContentTypeEnum.java <br/>
 *
 * @author ranyk           <br/>
 * @version V1.0           <br/>
 * @decription: ContentType 枚举  <br/>
 * @date: 2022-04-14 <br/>
 */
@Getter
@SuppressWarnings("unused")
public enum ContentTypeEnum {


    /**
     * application/vnd.ms-excel Content Type 定义
     */
    EXCEL_TYPE("application/vnd.ms-excel", "application/vnd.ms-excel Content Type 定义"),
    /**
     * text/html Content Type 定义
     */
    HTML_TYPE("text/html", "text/html Content Type 定义"),
    /**
     * text/javascript Content Type 定义
     */
    JS_TYPE("text/javascript", "text/javascript Content Type 定义"),
    /**
     * application/json Content Type 定义
     */
    JSON_TYPE("application/json", "application/json Content Type 定义"),
    /**
     * text/xml Content Type 定义
     */
    XML_TYPE("text/xml", "text/xml Content Type 定义"),
    /**
     * text/plain Content Type 定义
     */
    TEXT_TYPE("text/plain", "text/plain Content Type 定义");

    /**
     * content type 值
     */
    private final String value;
    /**
     * content type 信息
     */
    private final String msg;

    /**
     * 全参构造器
     *
     * @param value content type 值
     * @param msg   content type 信息
     */
    ContentTypeEnum(String value, String msg) {
        this.value = value;
        this.msg = msg;
    }

    /**
     * 根据content type 值获取 content type 枚举对象
     *
     * @param value content type 值
     * @return 反正状态枚举对象, 默认 ContentTypeEnum.JSON_TYPE
     */
    public static ContentTypeEnum stateOf(String value) {
        for (ContentTypeEnum statusEnum : values()) {
            if (Objects.equals(statusEnum.getValue(), value)) {
                return statusEnum;
            }
        }
        return JSON_TYPE;
    }

}
